<template>
  <div>
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" title="应用关联" @del="del" @newCreate="newCreate"></v-tableTitle>
    <GTable ref="table" api="/v1/plApplicationLink/selectPlApplicationLinkList" :columnSource="baseColumns" :hasCheck="true" :hasEdit="true" :cbFun="cbFun"
      @selection-change="data => tableSelectData = data" @setdialog="setdialog" />
  </div>
</template>

<script>
import tableTitle from 'commons/TableTitle'

export default {
  name: 'relevance',
  data() {
    return {
      tableSelectData: [],
      options: {
        company: [],
        type: [],
        status: []
      }
    }
  },
  computed: {
    btnConfig() {
      return [
        {
          label: this.$t('common.create'),
          invalid: 'newCreate',
          permi: ['timeTask:add']
        },
        {
          label: this.$t('common.delete'),
          disabled: true,
          invalid: 'del'
        }
      ]
    },
    baseColumns() {
      return [
        // {
        //   label: '公司名称',
        //   prop: 'companyId',
        //   input: 'select',
        //   options: this.options.company
        // },
        {
          label: '应用关联名称',
          prop: 'linkName',
          input: 'input',
          width:'250px'
        },
        // {
        //   label: '应用关联状态',
        //   prop: 'linkStatus',
        //   input: 'select',
        //   options: this.options.status
        // },
        {
          label: '应用关联描述',
          prop: 'linkDesc'
        },
        {
          label: this.$t('app.addName'),
          prop: 'insUser'
        },
        {
          label: this.$t('app.addDate'),
          prop: 'insTime'
        },
        {
          label: this.$t('app.updateName'),
          prop: 'updUser'
        },
        {
          label: this.$t('app.updateDate'),
          prop: 'updTime'
        }
      ]
    }
  },
  methods: {
    setdialog(data) {
      this.$router.push({
        path: '/app/relevanceDetail',
        query: { id: data.id }
      })
    },
    newCreate(){
      this.$router.push({
        path: '/app/relevanceDetail'
      })
    },
    del(data) {
      this.$post(
        '/v1/plApplicationLink/deletePlApplicationLinkByIds',
        data
      ).then(res => {
        this.$message.success(res.returnMgr)
        this.getTableData()
      })
    },
    getOptions(){
      this.$get('/system/codeLookup/LinkStatus').then(res => {
        this.options.status = res.data.item.map(i => {
          i.label = i.description
          i.value = i.code
          return i
        })
      })
    },
    cbFun(res) {
      return { list: res.data.page.records, total: res.data.page.total }
    },
    async getTableData() {
      this.$refs.table.getTableData()
    }
    //设置弹框
  },
  mounted() {
    this.getOptions()
  },
  components: {
    'v-tableTitle': tableTitle
  }
}
</script>

<style scoped>
</style>
